package com.trg.flex.messages
{
	import mx.controls.Alert;
	import mx.rpc.Fault;
	import mx.utils.ObjectUtil;
	
	public class ErrorMessageConvertor
	{
		public function ErrorMessageConvertor()
		{
		}
		
		private static var instance:ErrorMessageConvertor;
		
		public static function getInstance():ErrorMessageConvertor {
			if (instance == null) {
				instance = new ErrorMessageConvertor();
			}
			return instance;
		}
		
		public function getMessage(err:Error):Message {
			var msg:Message = new Message();
			msg.type = Message.TYPE_ERROR;
			
			if (err is Fault && Fault(err).faultString.indexOf("org.springframework.dao.DataIntegrityViolationException :") == 0) {
				msg.text = "The action cannot be performed because other items depend on this information.";
			} else {
				msg.text = "An unexpected Error occured.";
				Alert.show(ObjectUtil.toString(err));
			}
			return msg;
		}
	}
}